<template>
    <view>
        <view class="input-group">
            <view class="input-row">
                <view class="title">身份证</view>
                <m-input type="idcard" class="m-input input-frame" displayable v-model="identityNo"
                         placeholder="请输入18位身份证号码"></m-input>
            </view>
            <view class="input-row">
                <view class="title">学号</view>
                <m-input type="number" class="m-input input-frame" displayable v-model="studentNo"
                         placeholder="请输入12位学号"></m-input>
            </view>

            <view class="input-row">
                <view class="title">新密码</view>
                <m-input type="password" class="input-frame" displayable v-model="newPwd"
                         placeholder="请输入6到12位新密码"></m-input>
            </view>
            <view class="tip">(仅限6-12位数字和字母组合)</view>
            <view class="input-row">
                <view class="title">确定密码</view>
                <m-input type="password" class="input-frame" displayable v-model="newPassword"
                         placeholder="请再次输入6到12位密码"></m-input>
            </view>
            <view class="tip">(仅限6-12位数字和字母组合)</view>
            <view class="btn-row">
                <button type="primary" class="primary loginBtn" @tap="changePwd">确认修改</button>
            </view>


        </view>
    </view>
</template>

<script>
    import UserService from '@/services/user/index';
    import mInput from '@/components/common/m-input/m-input.vue'
    import mIcon from '@/components/common/m-icon/m-icon.vue'
    import mixins from '@/mixins/index';
	import md5 from 'js-md5';
    const userService = new UserService(false);
    //const pwdReg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,12}$/;//8到16位数字与字母组合
    export default {
        components: {
            mInput,
            mIcon
        },
        mixins:[mixins],
        data() {
            return {
                identityNo: '',
                studentNo:'',
                newPwd: '',
                newPassword: ''
            };
        },
        methods: {
            changePwd() {
                if (this.identityNo.length != 18) {
                    uni.showToast({
                        icon: 'none',
                        title: '请输入18位身份证号码'
                    });
                    return;
                }
                if (this.studentNo.length != 12) {
                    uni.showToast({
                        icon: 'none',
                        title: '请输入12位学号'
                    });
                    return;
                }
                if (this.newPwd.length < 6 || this.newPwd.length>12) {
                    uni.showToast({
                        icon: 'none',
                        title: '仅限6-12位数字和字母组合'
                    });
                    return;
                }
            
                if (this.newPassword.length < 6 || this.newPassword.length>12) {
                    uni.showToast({
                        icon: 'none',
                        title: '仅限6-12位数字和字母组合'
                    });
                    return;
                }
                if (this.newPwd!=this.newPassword) {
                    uni.showToast({
                        icon: 'none',
                        title: '两次密码不一致'
                    });
                    return;
                }
                let {identityNo,studentNo,newPwd} = this;
				newPwd = md5(newPwd);
                userService.forgetPwd({idCard:identityNo,studentId:studentNo,newPassWord:newPwd}).then((modifyPwd) => {
                    if(modifyPwd.success)
                    {
                        uni.navigateBack();
                    }else{
						uni.showToast({
							title:modifyPwd.message,
							icon:"none",
							duration:2000
						})
					}
                });

            }
        }
    };
</script>

<style lang="less" scoped>
    .input-group {
        padding: 0 30upx;
    }
    .input-row {
        border-bottom: 1px solid #f1f1f1;
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        align-items: center;
        padding: 20upx 0;
        font-size: 28upx;
    }
    .input-frame {
        font-size: 24upx;
        min-width: 500upx;
    }
    .btn-row {
        margin-top: 50upx;
    }
    .tip {
        color: #f1685d;
        font-size: 24upx;
        margin-top: 20upx;
    }
    .title {
        color: #333;
        font-size: 28upx;
        width: 145upx;
    }
</style>
